﻿Imports CompanyCloudService.BLL
Imports CompanyCloudService.DAL
Imports CompanyCloudService.DAL.SqlClient
Partial Public Class nettiers2
  Inherits System.Web.UI.Page

  Private Sub nettiers2_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
    Call CheckParameters()
    If Not (bParametersLoaded) Then Response.Redirect("/error.htm")
    If iIsInUpgrade Then Response.Redirect("/upgrade.htn")
  End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not (Page.IsPostBack) Then Call LoadValues()
  End Sub
  Sub LoadValues()
    Call BindMessages()
  End Sub
  Sub BindMessages()
    Dim oTstMessages As TList(Of TstMessage)

    oTstMessages = DataRepository.TstMessageProvider.GetAll()
    grdMesssages.DataSource = oTstMessages
    grdMesssages.DataBind()
    oTstMessages = Nothing
  End Sub
  Protected Sub butAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles butAdd.Click
    Call AddMessage(txtMessageNew.Text)
    Call BindMessages()
  End Sub
  Sub AddMessage(ByVal sMessageNew As String)
    Dim oTstMessage As TstMessage
    Dim iMessageID As Integer = 0

    oTstMessage = New TstMessage
    oTstMessage.Message = sMessageNew
    oTstMessage.CreatedDateTime = Now.ToUniversalTime
    DataRepository.TstMessageProvider.Insert(oTstMessage)
    iMessageID = oTstMessage.MessageID
    oTstMessage = Nothing
  End Sub
End Class